package main

import (
    "facecat"
    "io/ioutil"
    "fmt"
)

/*
* 树节点的点击事件
* tree:树
* node:节点
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
* clicks:点击次数
*/
func OnClickTreeNode(tree *facecat.FCView, node *facecat.FCTreeNode, firstTouch bool, firstPoint facecat.FCPoint, secondTouch bool, secondPoint facecat.FCPoint, clicks int){
    fmt.Println(node.Value)
}

var gPaint = new(facecat.FCPaint)

func WndProc(hwnd facecat.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
    return facecat.WndProcDefault(gPaint, hwnd, msg, wParam, lParam)
}

func main() {
    gPaint = facecat.CreatePaint()
    gPaint.OnClickTreeNode = OnClickTreeNode
    facecat.CreateMainWindow(gPaint, "FaceCat-Go", WndProc)
    xmlStr, _ := ioutil.ReadFile("xml//treeexample.xml")
    facecat.RenderFaceCat(gPaint, string(xmlStr))
    //获取第二页
    tree := facecat.FindViewByName("Tree", gPaint.Views)
    tree.GetTree().HeaderHeight = 0
    tree.GetTree().ShowCheckBox = true
    column := facecat.CreateTreeColumn()
    column.Width = 500
    tree.GetTree().Columns = append(tree.GetTree().Columns, column)
       
    rootNode := facecat.CreateTreeNode()
    rootNode.Value = "证监会行业类"
    noneNode := new(facecat.FCTreeNode)
    noneNode.IsNotEmpty = false
    facecat.AppendTreeNode(tree, rootNode, noneNode)

    node1 := facecat.CreateTreeNode()
    node1.Value = "农、林、牧、渔业"
    facecat.AppendTreeNode(tree, node1, rootNode)

    var strs1 []string
    strs1 = append(strs1, "农业")
    strs1 = append(strs1, "林业")
    strs1 = append(strs1, "畜牧业")
    strs1 = append(strs1, "渔业")
    strs1 = append(strs1, "农、林、牧、渔服务业")
    for i := 0; i < len(strs1); i++{
	    subNode1 := facecat.CreateTreeNode()
	    subNode1.Value = strs1[i]
	    facecat.AppendTreeNode(tree, subNode1, node1)
    }

    node2 := facecat.CreateTreeNode()
    node2.Value = "采矿业"
    facecat.AppendTreeNode(tree, node2, rootNode)

    var strs2 []string
    strs2 = append(strs2, "煤炭开采和洗选业")
    strs2 = append(strs2, "石油和天然气开采业")
    strs2 = append(strs2, "黑色金属矿采选业")
    strs2 = append(strs2, "有色金属矿采选业")
    strs2 = append(strs2, "非金属矿采选业")
    strs2 = append(strs2, "开采辅助活动")
    for i := 0; i < len(strs2); i++{
	    subNode2 := facecat.CreateTreeNode()
	    subNode2.Value = strs2[i]
	    facecat.AppendTreeNode(tree, subNode2, node2)
    }

    node3 := facecat.CreateTreeNode()
    node3.Value = "制造业"
    facecat.AppendTreeNode(tree, node3, rootNode)

    var strs3 []string
    strs3 = append(strs3, "农副食品加工业")
    strs3 = append(strs3, "食品制造业")
    strs3 = append(strs3, "酒、饮料和精制茶制造业")
    strs3 = append(strs3, "纺织业")
    strs3 = append(strs3, "纺织服装、服饰业")
    strs3 = append(strs3, "皮革、毛皮、羽毛及其制品和制鞋业")
    strs3 = append(strs3, "木材加工和木、竹、藤、棕、草制品业")
    strs3 = append(strs3, "家具制造业")
    strs3 = append(strs3, "造纸和纸制品业")
    strs3 = append(strs3, "印刷和记录媒介复制业")
    strs3 = append(strs3, "文教、工美、体育和娱乐用品制造业")
    strs3 = append(strs3, "石油加工、炼焦和核燃料加工业")
    strs3 = append(strs3, "化学原料及化学制品制造业")
    strs3 = append(strs3, "医药制造业")
    strs3 = append(strs3, "化学纤维制造业")
    strs3 = append(strs3, "橡胶和塑料制品业")
    strs3 = append(strs3, "非金属矿物制品业")
    strs3 = append(strs3, "黑色金属冶炼和压延加工业")
    strs3 = append(strs3, "有色金属冶炼和压延加工业")
    strs3 = append(strs3, "金属制品业")
    strs3 = append(strs3, "通用设备制造业")
    strs3 = append(strs3, "专用设备制造业")
    strs3 = append(strs3, "汽车制造业")
    strs3 = append(strs3, "铁路、船舶、航空航天和其他运输设备制造业")
    strs3 = append(strs3, "电气机械和器材制造业")
    strs3 = append(strs3, "计算机、通信和其他电子设备制造业")
    strs3 = append(strs3, "仪器仪表制造业")
    strs3 = append(strs3, "其他制造业")
    strs3 = append(strs3, "废弃资源综合利用业")
    for i := 0; i < len(strs3); i++{
	    subNode3 := facecat.CreateTreeNode()
	    subNode3.Value = strs3[i]
	    facecat.AppendTreeNode(tree, subNode3, node3)
    }
    facecat.Invalidate(gPaint)
    facecat.ShowWindow(gPaint)
}